home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 January: Mac OS SDK / Dev.CD Jan 99 SDK1.toast / Development Kits / Interfaces&Libraries / Universal / Interfaces / PInterfaces / Math64.p < prev    next >
Encoding:
Text File  |  1998-08-17  |  7.8 KB  |  224 lines  |  [TEXT/MPS ]

  1. {
  2.      File:        Math64.p
  3.  
  4.      Contains:    64-bit integer math Interfaces.
  5.  
  6.      Version:    Technology:    System 7.5
  7.                  Release:    Universal Interfaces 3.2
  8.  
  9.      Copyright:    © 1994-1998 by Apple Computer, Inc., all rights reserved
  10.  
  11.      Bugs?:        For bug reports, consult the following page on
  12.                  the World Wide Web:
  13.  
  14.                      http://developer.apple.com/bugreporter/
  15.  
  16. }
  17. {$IFC UNDEFINED UsingIncludes}
  18. {$SETC UsingIncludes := 0}
  19. {$ENDC}
  20.  
  21. {$IFC NOT UsingIncludes}
  22.  UNIT Math64;
  23.  INTERFACE
  24. {$ENDC}
  25.  
  26. {$IFC UNDEFINED __MATH64__}
  27. {$SETC __MATH64__ := 1}
  28.  
  29. {$I+}
  30. {$SETC Math64Includes := UsingIncludes}
  31. {$SETC UsingIncludes := 1}
  32.  
  33. {$IFC UNDEFINED __CONDITIONALMACROS__}
  34. {$I ConditionalMacros.p}
  35. {$ENDC}
  36. {$IFC UNDEFINED __MACTYPES__}
  37. {$I MacTypes.p}
  38. {$ENDC}
  39.  
  40.  
  41. {$PUSH}
  42. {$ALIGN MAC68K}
  43. {$LibExport+}
  44.  
  45.  
  46. {--------------------------------------------------------------------------------
  47.                 These routines are intended to provide C software support for
  48.                 64 bit integer types.  Their behavior should mimic anticipated
  49.                 64 bit hardware. This implementation should replace use of the
  50.                 "wide" type found in PowerPC.
  51.  
  52.     The following routines are available for performing math on 64-bit integers:
  53.     
  54.     S64Max
  55.                 Returns the largest representable SInt64.
  56.     S64Min
  57.                 Returns the smallest (i.e. most negative) SInt64.  Note: the negative
  58.                 (absolute value) of this number is not representable in an SInt64.
  59.                 That means that S64Negate(S64Min) is not representable (in fact,
  60.                 it returns S64Min).
  61.     S64Add
  62.                 Adds two integers, producing an integer result.  If an overflow
  63.                 occurs the result is congruent mod (2^64) as if the operands and
  64.                 result were unsigned.  No overflow is signaled.
  65.     
  66.     S64Subtract
  67.                 Subtracts two integers, producing an integer result.  If an overflow
  68.                 occurs the result is congruent mod (2^64) as if the operands and
  69.                 result were unsigned.  No overflow is signaled.
  70.  
  71.     S64Negate
  72.                 Returns the additive inverse of a signed number (i.e. it returns
  73.                 0 - the number).  S64Negate (S64Min) is not representable (in fact,
  74.                 it returns S64Min).
  75.     
  76.     S64Absolute
  77.                 Returns the absolute value of the number (i.e. the number if
  78.                 it is positive, or 0 - the number if it is negative).
  79.                 See S64Negate above.
  80.                 
  81.     S64Multiply
  82.                 Multiplies two signed numbers, producing a signed result.  Overflow
  83.                 is ignored and the low-order part of the product is returned.  The
  84.                 sign of the result is not guaranteed to be correct if the magnitude
  85.                 of the product is not representable.
  86.                 
  87.     S64Div
  88.                 Divides dividend by divisor, returning the quotient.  
  89.  
  90.     S64Divide
  91.                 Divides dividend by divisor, returning the quotient.  The remainder
  92.                 is returned in *remainder if remainder (the pointer) is non-NULL.
  93.                 The sign of the remainder is the same as the sign of the dividend
  94.                 (i.e. it takes the absolute values of the operands, does the division,
  95.                 then fixes the sign of the quotient and remainder).  If the divisor
  96.                 is zero, then S64Max() will be returned (or S64Min() if the dividend
  97.                 is negative), and the remainder will be the dividend; no error is
  98.                 reported.
  99.     
  100.     S64Set
  101.                 Given an SInt32, returns an SInt64 with the same value.  Use this
  102.                 routine instead of coding 64-bit constants (at least when the
  103.                 constant will fit in an SInt32).
  104.     
  105.     S64SetU
  106.                 Given a UInt32, returns a SInt64 with the same value.
  107.     
  108.     S64Compare
  109.                 Given two signed numbers, left and right, returns an
  110.                 SInt32 that compares with zero the same way left compares with
  111.                 right.  If you wanted to perform a comparison on 64-bit integers
  112.                 of the form:
  113.                         operand_1 <operation> operand_2
  114.                 then you could use an expression of the form:
  115.                         xxxS64Compare(operand_1,operand_2) <operation> 0
  116.                 to test for the same condition.
  117.                 
  118.                 CAUTION: DO NOT depend on the exact value returned by this routine.
  119.                 Only the sign (i.e. positive, zero, or negative) of the result is
  120.                 guaranteed.
  121.  
  122.     S64And, S64Or, S64Eor and S64Not
  123.     
  124.                 Return Boolean (1 or 0) depending on the outcome of the logical
  125.                 operation.
  126.  
  127.     S64BitwiseAnd, S64BitwiseOr, S64BitwiseEor and S64BitwiseNot
  128.     
  129.                 Return the Bitwise result.
  130.                 
  131.     S64ShiftRight and S64ShiftLeft
  132.     
  133.                 The lower 7 bits of the shift argument determines the amount of 
  134.                 shifting.  S64ShiftRight is an arithmetic shift while U64ShiftRight
  135.                 is a logical shift.
  136.  
  137.     SInt64ToLongDouble
  138.                 
  139.                 Converts SInt64 to long double.  Note all SInt64s fit exactly into 
  140.                 long doubles, thus, the binary -> decimal conversion routines
  141.                 in fp.h can be used to achieve SInt64 -> long double -> decimal
  142.                 conversions.
  143.                 
  144.     LongDoubleToSInt64
  145.     
  146.                 Converts a long double to a SInt64.  Any decimal string that fits
  147.                 into a SInt64 can be converted exactly into a long double, using the
  148.                 conversion routines found in fp.h.  Then this routine can be used
  149.                 to complete the conversion to SInt64.
  150.                 
  151.     SInt64ToWide
  152.     
  153.                 Converts a SInt64 to a wide struct.  If SInt64 is implemented
  154.                 as a typedef of wide, the marco does nothing. If SInt64 is 
  155.                 implememnted as a long long, it casts the long long into a 
  156.                 wide struct.
  157.     
  158.     WideToSInt64
  159.     
  160.                 Converts a wide struct into a SInt64.  If SInt64 is implemented
  161.                 as a typedef of wide, the marco does nothing. If SInt64 is 
  162.                 implememnted as a long long, it reads the struct into a long long.
  163.     
  164.     
  165.     The corresponding UInt64 routines are also included.
  166.     
  167. --------------------------------------------------------------------------------}
  168.  
  169. FUNCTION S64Max: SInt64; C;
  170. FUNCTION S64Min: SInt64; C;
  171. FUNCTION S64Add(x: SInt64; y: SInt64): SInt64; C;
  172. FUNCTION S64Subtract(left: SInt64; right: SInt64): SInt64; C;
  173. FUNCTION S64Negate(value: SInt64): SInt64; C;
  174. FUNCTION S64Absolute(value: SInt64): SInt64; C;
  175. FUNCTION S64Multiply(xparam: SInt64; yparam: SInt64): SInt64; C;
  176. FUNCTION S64Divide(dividend: SInt64; divisor: SInt64; VAR remainder: SInt64): SInt64; C;
  177. FUNCTION S64Set(value: SInt32): SInt64; C;
  178. FUNCTION S64SetU(value: UInt32): SInt64; C;
  179. FUNCTION S32Set(value: SInt64): SInt32; C;
  180. FUNCTION S64Compare(left: SInt64; right: SInt64): LONGINT; C;
  181. FUNCTION S64And(left: SInt64; right: SInt64): BOOLEAN; C;
  182. FUNCTION S64Or(left: SInt64; right: SInt64): BOOLEAN; C;
  183. FUNCTION S64Eor(left: SInt64; right: SInt64): BOOLEAN; C;
  184. FUNCTION S64Not(value: SInt64): BOOLEAN; C;
  185. FUNCTION S64BitwiseAnd(left: SInt64; right: SInt64): SInt64; C;
  186. FUNCTION S64BitwiseOr(left: SInt64; right: SInt64): SInt64; C;
  187. FUNCTION S64BitwiseEor(left: SInt64; right: SInt64): SInt64; C;
  188. FUNCTION S64BitwiseNot(value: SInt64): SInt64; C;
  189. FUNCTION S64ShiftRight(value: SInt64; shift: UInt32): SInt64; C;
  190. FUNCTION S64ShiftLeft(value: SInt64; shift: UInt32): SInt64; C;
  191. FUNCTION U64Max: UInt64; C;
  192. FUNCTION U64Add(x: UInt64; y: UInt64): UInt64; C;
  193. FUNCTION U64Subtract(left: UInt64; right: UInt64): UInt64; C;
  194. FUNCTION U64Multiply(xparam: UInt64; yparam: UInt64): UInt64; C;
  195. FUNCTION U64Divide(dividend: UInt64; divisor: UInt64; VAR remainder: UInt64): UInt64; C;
  196. FUNCTION U64Set(value: SInt32): UInt64; C;
  197. FUNCTION U64SetU(value: UInt32): UInt64; C;
  198. FUNCTION U32SetU(value: UInt64): UInt32; C;
  199. FUNCTION U64Compare(left: UInt64; right: UInt64): LONGINT; C;
  200. FUNCTION U64And(left: UInt64; right: UInt64): BOOLEAN; C;
  201. FUNCTION U64Or(left: UInt64; right: UInt64): BOOLEAN; C;
  202. FUNCTION U64Eor(left: UInt64; right: UInt64): BOOLEAN; C;
  203. FUNCTION U64Not(value: UInt64): BOOLEAN; C;
  204. FUNCTION U64BitwiseAnd(left: UInt64; right: UInt64): UInt64; C;
  205. FUNCTION U64BitwiseOr(left: UInt64; right: UInt64): UInt64; C;
  206. FUNCTION U64BitwiseEor(left: UInt64; right: UInt64): UInt64; C;
  207. FUNCTION U64BitwiseNot(value: UInt64): UInt64; C;
  208. FUNCTION U64ShiftRight(value: UInt64; shift: UInt32): UInt64; C;
  209. FUNCTION U64ShiftLeft(value: UInt64; shift: UInt32): UInt64; C;
  210. FUNCTION UInt64ToSInt64(value: UInt64): SInt64; C;
  211. FUNCTION SInt64ToUInt64(value: SInt64): UInt64; C;
  212.  
  213.  
  214. {$ALIGN RESET}
  215. {$POP}
  216.  
  217. {$SETC UsingIncludes := Math64Includes}
  218.  
  219. {$ENDC} {__MATH64__}
  220.  
  221. {$IFC NOT UsingIncludes}
  222.  END.
  223. {$ENDC}
  224.